package com.ym.b2b.order.controller;

import javax.servlet.http.HttpServletRequest;

import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.ym.b2b.order.service.WebServiceOrderService;
import com.ym.b2b.order.sqlbean.WebServiceOrder;
import com.ym.b2b.ws.service.ForERPService;

/** 
 * @ClassName: WebServiceOrderController 
 * @Author cym
 * @Date 2016年9月22日 下午4:08:14 
 * @Modify  
 * @CopyRight 珍诚医药在线股份有限公司 
 */
@Controller
@RequestMapping("/web")
public class WebServiceOrderController {
	

    @Autowired
    private WebServiceOrderService 				service;

    @RequestMapping("getOrderForERP.do")
    @ResponseBody
    public String getOrderForERP(WebServiceOrder order, HttpServletRequest req) {
    	JaxWsProxyFactoryBean factoryBean = new JaxWsProxyFactoryBean();
        factoryBean.setServiceClass(ForERPService.class);
//        factoryBean.setAddress("http://localhost:8080/admin/ws/ForERPServiceService?wsdl");
        factoryBean.setAddress("http://localhost:1800/admin/ws/ForERPServiceService?wsdl");
        ForERPService service = (ForERPService)factoryBean.create();
        String str = service.getOrderList(order.getStartDate(), order.getEndDate(), String.valueOf(order.getStatus()));
        System.out.println(str);
        return str;
    }
    
    @RequestMapping("updateOrder.do")
    @ResponseBody
    public String updateOrder(WebServiceOrder order, HttpServletRequest req) {
    	System.out.println(JSON.toJSONString(order));
    	JaxWsProxyFactoryBean factoryBean = new JaxWsProxyFactoryBean();
        factoryBean.setServiceClass(ForERPService.class);
//        factoryBean.setAddress("http://localhost:8080/admin/ws/ForERPServiceService?wsdl");
        factoryBean.setAddress("http://localhost:1800/admin/ws/ForERPServiceService?wsdl");
        ForERPService service = (ForERPService)factoryBean.create();
        String str = service.updateOrder(order.getOrderCode(), order.getOrderCodeErp(), String.valueOf(order.getStatus()),null);
        System.out.println(str);
        return str;
    }
    
}
